<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" :width="900" destroy-on-close @closed="$emit('closed')">
		<el-form :model="form" :rules="rules" :disabled="mode=='show'" ref="dialogForm" label-width="auto" label-position="right">
			<el-row :gutter="20">
			  <el-col :span="8">
				<el-form-item label="反馈类型" prop="feedback_type">
					<el-select v-model="form.feedback_type" style="width: 100%;">
  					  <el-option v-for="item in $parent.feedbackTypeLabel"
  					    :key="item.value" :label="item.label" :value="item.value">
  					  </el-option>
  					</el-select>
				</el-form-item>
			  </el-col>
              <el-col :span="8">
				<el-form-item label="联系电话" prop="target">
					<el-input v-model="form.mobile"></el-input>
				</el-form-item>
			  </el-col>
			  <el-col :span="24">
			  	<el-form-item label="问题描述" prop="problem">
					<el-input type="textarea" v-model="form.problem" :rows="3"></el-input>
				</el-form-item>
			  </el-col>
			  <el-col :span="24">
			  	<el-form-item label="反馈附件" prop="enclosures">
                    <el-image style="width: 100px; height: 100px; margin-right: 10px;" v-for="(img, i) in form.enclosures" :key="i"
                      :src="img" :preview-src-list="[img]" :initial-index="1" fit="cover" :alt="url + img"
                    />
				</el-form-item>
			  </el-col>
			</el-row>
		</el-form>
		<template #footer>
			<el-button @click="submit()" >关 闭</el-button>
		</template>
	</el-dialog>
</template>

<script>
	export default {
		emits: ['success', 'closed'],
		data() {
			return {
				mode: "add",
				url: process.env.VUE_APP_FILES_URL,
				titleMap: {
					add: '新增',
					edit: '编辑',
					show: '查看'
				},
				visible: false,
				isSaveing: false,
				parentSearch: {},
				//表单数据
				form: {
					id: 0,
					feedback_type: '',
					title: '',
					image: '',
					jump_type: 0,
					target: '',
					sort: 0,
					status: 1,
				},
				//验证规则
				rules: {
					feedback_type: [
						{required: true, message: '反馈类型'}
					],
				}
			}
		},
		mounted() {
			
		},
		methods: {
			open(mode='add', search){
				this.parentSearch = search
				this.mode = mode;
				this.visible = true;
				return this
			},
			//跳转
			async feedbackInfo(e) {
				var res = await this.$API.platform.feedback.info.get({id: e})
				if(res.code == 200) {
					this.form = res.data
				} else {
					this.$alert(res.message, "提示", {type: 'error'})
				} 
			},
			//表单提交方法
			submit() {
				this.visible = false
				this.$emit('success', this.mode, this.parentSearch)
			},
			//表单注入数据
			setData(data) {
				this.feedbackInfo(data.id)
				//可以和上面一样单个注入，也可以像下面一样直接合并进去
				//Object.assign(this.form, data)
			}
		}
	}
</script>

<style>
</style>
